#include <cstdio>
#include <queue>
#include <map>

using namespace std;

int li[ 13 ][ 5 ] = { { 2, -1 }, { 2, 5, -1 }, { 0, 1, 3, 6, -1 }, { 2, 7, -1 }, { 5, -1 },
            { 1, 4, 6, 9, -1 }, { 2, 5, 7, 10, -1 }, { 3, 6, 8, 11, -1 }, { 7, -1 },
            { 5, 10, -1 }, { 6, 9, 11, 12, -1 }, { 7, 10, -1 }, { 10, -1 } };

struct Node
{
    int a[ 13 ];
};

bool operator < ( const Node &a, const Node &b )
{
    int i;
    for ( i = 0; i < 13; i++ )
        if ( a.a[ i ] != b.a[ i ] )
            return a.a[ i ] < b.a[ i ];
    return false;
}

bool check( Node a )
{
    int i;
    for ( i = 1; i <= 11; i++ )
        if ( a.a[ i ] != i )
            return false;
    return true;
}

map<Node, pair<int, bool> > m;
queue<pair<Node, bool> >q;
bool ok;

void init( )
{
    Node p;
    int i;
    m.clear( );
    ok = false;
    while ( !q.empty( ) ) q.pop( );
    for ( i = 0; i < 13; i++ )
        scanf("%d", &p.a[ i ]);
    if ( check( p ) )
    {
        puts("0");
        ok = true;
        return ;
    }
    q.push( pair<Node, bool>( p, 0 ) );
    m[ p ] = pair<int, bool>( 0, 0 );
    for ( i = 0; i < 13; i++ )
        p.a[ i ] = i;
    p.a[ 12 ] = 0;
    q.push( pair<Node, bool>( p, 1 ) );
    m[ p ] = pair<int, bool>( 0, 1 );
}

void work( )
{
    map<Node, pair<int, bool> >::iterator it;
    Node p;
    bool flag;
    int cnt, i, j, t;
    while ( !q.empty( ) )
    {
        p = q.front( ).first;
        flag = q.front( ).second;
        q.pop( );
        cnt = m[ p ].first;
        if ( cnt > 10 ) break;
        for ( i = 0; i < 13; i++ )
            if ( !p.a[ i ] )
                for ( j = 0; li[ i ][ j ] != -1; j++ )
                {
                    t = p.a[ i ];
                    p.a[ i ] = p.a[ li[ i ][ j ] ];
                    p.a[ li[ i ][ j ] ] = t;
                    it = m.find( p );
                    if ( it != m.end( ) )
                    {
                        if ( m[ p ].second != flag )
                        {
                            if ( cnt + 1 + m[ p ].first > 20 )
                            {
                                puts("No solution!");
                                return ;
                            }
                            printf("%d\n", cnt + 1 + m[ p ].first);
                            return ;
                        }
                    }
                    else
                    {
                        m[ p ] = pair<int, bool>( cnt + 1, flag );
                        q.push( pair<Node, bool>( p, flag ) );
                    }
                    t = p.a[ i ];
                    p.a[ i ] = p.a[ li[ i ][ j ] ];
                    p.a[ li[ i ][ j ] ] = t;
                }
    }
    printf("No solution!\n");
}

int main( )
{
    int t;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        if ( ok ) continue;
        work( );
    }
    return 0;
}
